#!/usr/bin/env python3
#Validation module

def dateYear(year):
    try:
        y = int(year)
        if (y < 1800) or (y > 2200):
            return False
        else:
            return True
    except ValueError:
        return False

def dateMonth(month):
    if (month.find('<') > -1) or (month.find('>') > -1): # contains sentinels
        return False
    ''' The sentinels in the following string prevent the user from enter
        something like N<> as a legal month. '''
    months = "<JAN><FEB><MAR><APR><MAY><JUN><JUL><AUG><SEP><OCT><NOV><DEC>"
    if month.upper() in months:
        return True
    else:
        return False


def dateDay(day,month,year):
    '''We know that the month formats are correct so we do not need sentinels.'''
    month30 = "SEPAPRJUNNOV"
    month28 = "FEB"
    try:
        d = int(day)
        if (d < 1) or (d > 31): # make sure between 1 and 31 days
            return False
    except ValueError:
        return False
    if month.upper() in month30:
        if d > 30:
            return False
    if month.upper() in month28:
        if int(year)%4 == 0 and (int(year)%100 != 0 or int(year)%400 == 0):
            if d <= 29:
                return True
            else:
                return False
        else:
            if d > 28:
                return False
    return True



